

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>8.1. KDTree — MDAnalysis.KDTree.KDTree &mdash; MDAnalysis v0.7.5-devel documentation</title>
    <link rel="stylesheet" href="../../_static/sphinxdoc.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../../',
        VERSION:     '0.7.5-devel',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../_static/doctools.js"></script>
    <link rel="search" type="application/opensearchdescription+xml"
          title="Search within MDAnalysis v0.7.5-devel documentation"
          href="../../_static/opensearch.xml"/>
    <link rel="shortcut icon" href="../../_static/mdanalysis-logo.ico"/>
    <link rel="top" title="MDAnalysis v0.7.5-devel documentation" href="../../index.html" />
    <link rel="up" title="8. KDTree module" href="../KDTree_modules.html" />
    <link rel="next" title="8.2. Fast atom neighbor lookup using a KD tree (implemented in C++) — MDAnalysis.KDTree.NeighborSearch" href="NeighborSearch.html" />
    <link rel="prev" title="8. KDTree module" href="../KDTree_modules.html" /> 
  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="NeighborSearch.html" title="8.2. Fast atom neighbor lookup using a KD tree (implemented in C++) — MDAnalysis.KDTree.NeighborSearch"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="../KDTree_modules.html" title="8. KDTree module"
             accesskey="P">previous</a> |</li>
        <li><a href="../../index.html">MDAnalysis v0.7.5-devel documentation</a> &raquo;</li>
          <li><a href="../KDTree_modules.html" accesskey="U">8. KDTree module</a> &raquo;</li> 
      </ul>
    </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
            <p class="logo"><a href="../../index.html">
              <img class="logo" src="../../_static/mdanalysis-logo-200x150.png" alt="Logo"/>
            </a></p>
  <h4>Previous topic</h4>
  <p class="topless"><a href="../KDTree_modules.html"
                        title="previous chapter">8. KDTree module</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="NeighborSearch.html"
                        title="next chapter">8.2. Fast atom neighbor lookup using a KD tree (implemented in C++) &#8212; <tt class="docutils literal"><span class="pre">MDAnalysis.KDTree.NeighborSearch</span></tt></a></p>
  <h3>This Page</h3>
  <ul class="this-page-menu">
    <li><a href="../../_sources/documentation_pages/KDTree/KDTree.txt"
           rel="nofollow">Show Source</a></li>
  </ul>
<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="../../search.html" method="get">
      <input type="text" name="q" size="18" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <span class="target" id="module-MDAnalysis.KDTree.KDTree"></span><div class="section" id="kdtree-mdanalysis-kdtree-kdtree">
<h1>8.1. KDTree &#8212; <a class="reference internal" href="#module-MDAnalysis.KDTree.KDTree" title="MDAnalysis.KDTree.KDTree"><tt class="xref py py-mod docutils literal"><span class="pre">MDAnalysis.KDTree.KDTree</span></tt></a><a class="headerlink" href="#kdtree-mdanalysis-kdtree-kdtree" title="Permalink to this headline">¶</a></h1>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Author:</th><td class="field-body">Thomas Hamelryck, Oliver Beckstein</td>
</tr>
<tr class="field"><th class="field-name">Year:</th><td class="field-body">2002, 2008</td>
</tr>
<tr class="field"><th class="field-name">License:</th><td class="field-body">BSD</td>
</tr>
</tbody>
</table>
<p>The KD tree data structure can be used for all kinds of searches that
involve N-dimensional vectors, e.g.  neighbor searches (find all points
within a radius of a given point) or finding all point pairs in a set
that are within a certain radius of each other. See &#8220;Computational Geometry:
Algorithms and Applications&#8221; (Mark de Berg, Marc van Kreveld, Mark Overmars,
Otfried Schwarzkopf) <a class="reference internal" href="../KDTree_modules.html#deberg2000">[deBerg2000]</a>.</p>
<dl class="class">
<dt id="MDAnalysis.KDTree.KDTree.KDTree">
<em class="property">class </em><tt class="descclassname">MDAnalysis.KDTree.KDTree.</tt><tt class="descname">KDTree</tt><big>(</big><em>dim</em>, <em>bucket_size=10</em><big>)</big><a class="headerlink" href="#MDAnalysis.KDTree.KDTree.KDTree" title="Permalink to this definition">¶</a></dt>
<dd><p>KD tree implementation (C++, SWIG python wrapper)</p>
<p>The KD tree data structure can be used for all kinds of searches that
involve N-dimensional vectors, e.g.  neighbor searches (find all points
within a radius of a given point) or finding all point pairs in a set
that are within a certain radius of each other.</p>
<p>Reference:</p>
<p>Computational Geometry: Algorithms and Applications
Second Edition
Mark de Berg, Marc van Kreveld, Mark Overmars, Otfried Schwarzkopf
published by Springer-Verlag
2nd rev. ed. 2000.
ISBN: 3-540-65620-0</p>
<p>The KD tree data structure is described in chapter 5, pg. 99 of <a class="reference internal" href="../KDTree_modules.html#deberg2000">[deBerg2000]</a>.</p>
<p>The following article <a class="reference internal" href="../KDTree_modules.html#bentley1990">[Bentley1990]</a> made clear to me that the nodes should
contain more than one point (this leads to dramatic speed
improvements for the &#8220;all fixed radius neighbor search&#8221;, see
below):</p>
<p>JL Bentley, &#8220;Kd trees for semidynamic point sets,&#8221; in Sixth Annual ACM
Symposium on Computational Geometry, vol. 91. San Francisco, 1990</p>
<p>This KD implementation also performs a &#8220;all fixed radius neighbor search&#8221;,
i.e. it can find all point pairs in a set that are within a certain radius
of each other. As far as I know the algorithm has not been published.</p>
<p>Set up a KDTree for &lt;dim&gt; dimensions and &lt;bucket_size&gt; points per node.</p>
<p>kdt = KDTree(&lt;dim&gt;,bucket_size=&lt;n&gt;)</p>
<p>For &#8220;all fixed radius neighbor search&#8221; as typically used in
MDAnalysis, use a value such as bucket_size=10; for the
classical KD-tree use 1.</p>
<dl class="method">
<dt id="MDAnalysis.KDTree.KDTree.KDTree.all_get_indices">
<tt class="descname">all_get_indices</tt><big>(</big><big>)</big><a class="headerlink" href="#MDAnalysis.KDTree.KDTree.KDTree.all_get_indices" title="Permalink to this definition">¶</a></dt>
<dd><p>Return All Fixed Neighbor Search results.</p>
<p>Return a Nx2 dim Numeric array containing the indices of the point
pairs, where N is the number of neighbor pairs.</p>
</dd></dl>

<dl class="method">
<dt id="MDAnalysis.KDTree.KDTree.KDTree.all_get_radii">
<tt class="descname">all_get_radii</tt><big>(</big><big>)</big><a class="headerlink" href="#MDAnalysis.KDTree.KDTree.KDTree.all_get_radii" title="Permalink to this definition">¶</a></dt>
<dd><p>Return All Fixed Neighbor Search results.</p>
<p>Return an N-dim array containing the distances of all the point
pairs, where N is the number of neighbor pairs.</p>
</dd></dl>

<dl class="method">
<dt id="MDAnalysis.KDTree.KDTree.KDTree.all_search">
<tt class="descname">all_search</tt><big>(</big><em>radius</em><big>)</big><a class="headerlink" href="#MDAnalysis.KDTree.KDTree.KDTree.all_search" title="Permalink to this definition">¶</a></dt>
<dd><p>All fixed neighbor search.</p>
<p>Search all point pairs that are within radius.</p>
<p>o radius - float (&gt;0)</p>
</dd></dl>

<dl class="method">
<dt id="MDAnalysis.KDTree.KDTree.KDTree.get_indices">
<tt class="descname">get_indices</tt><big>(</big><big>)</big><a class="headerlink" href="#MDAnalysis.KDTree.KDTree.KDTree.get_indices" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the list of indices.</p>
<p>Return the list of indices after a neighbor search.  The indices
refer to the original coords numpy array. The coordinates with
these indices were within radius of center.</p>
<p>For an index pair, the first index&lt;second index.</p>
</dd></dl>

<dl class="method">
<dt id="MDAnalysis.KDTree.KDTree.KDTree.get_radii">
<tt class="descname">get_radii</tt><big>(</big><big>)</big><a class="headerlink" href="#MDAnalysis.KDTree.KDTree.KDTree.get_radii" title="Permalink to this definition">¶</a></dt>
<dd><p>Return radii.</p>
<p>Return the list of distances from center after a neighbor search.</p>
</dd></dl>

<dl class="method">
<dt id="MDAnalysis.KDTree.KDTree.KDTree.list_search">
<tt class="descname">list_search</tt><big>(</big><em>centers</em>, <em>radius</em><big>)</big><a class="headerlink" href="#MDAnalysis.KDTree.KDTree.KDTree.list_search" title="Permalink to this definition">¶</a></dt>
<dd><p>Search all points within radius of any center (radii NOT available).</p>
</dd></dl>

<dl class="method">
<dt id="MDAnalysis.KDTree.KDTree.KDTree.search">
<tt class="descname">search</tt><big>(</big><em>center</em>, <em>radius</em><big>)</big><a class="headerlink" href="#MDAnalysis.KDTree.KDTree.KDTree.search" title="Permalink to this definition">¶</a></dt>
<dd><p>Search all points within radius of center.</p>
<p>o center - one dimensional numpy array. E.g. if the
points have dimensionality D, the center array should have length D.
o radius - float&gt;0</p>
<p>center is always cast to numpy.float32</p>
</dd></dl>

<dl class="method">
<dt id="MDAnalysis.KDTree.KDTree.KDTree.set_coords">
<tt class="descname">set_coords</tt><big>(</big><em>coords</em><big>)</big><a class="headerlink" href="#MDAnalysis.KDTree.KDTree.KDTree.set_coords" title="Permalink to this definition">¶</a></dt>
<dd><p>Add the coordinates of the points.</p>
<p>o coords - two dimensional numpy array. E.g. if the
points have dimensionality D and there are N points, the coords
array should be NxD dimensional.</p>
<p>The coords array is always cast to a numpy.float32 array.</p>
</dd></dl>

</dd></dl>

</div>


          </div>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="NeighborSearch.html" title="8.2. Fast atom neighbor lookup using a KD tree (implemented in C++) — MDAnalysis.KDTree.NeighborSearch"
             >next</a> |</li>
        <li class="right" >
          <a href="../KDTree_modules.html" title="8. KDTree module"
             >previous</a> |</li>
        <li><a href="../../index.html">MDAnalysis v0.7.5-devel documentation</a> &raquo;</li>
          <li><a href="../KDTree_modules.html" >8. KDTree module</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
        &copy; Copyright 2005-2011, Naveen Michaud-Agrawal, Elizabeth J. Denning, Joshua Adelman,
    Christian Beckstein (logo), David Caplan, Jan Domański, Philip Fowler,
    Joseph Goose, Benjamin Hall, Danny Parton, Tyler Reddy, Paul Rigor,
    and Oliver Beckstein.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.7.
    </div>
  </body>
</html>